#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'json序列化'

import json


def JSON2Coder(coder):
    return Coder(coder['name'], coder['type'])


class Coder(object):

    def __init__(self, name, type):
        self.name = name
        self.type = type


coder = Coder('毛毛', '前端开发工程师')

cj = json.dumps(coder.__dict__, ensure_ascii=False)
print(cj)  # {"name": "毛毛", "type": "前端开发工程师"}

code = json.loads(cj, object_hook=JSON2Coder)
print(code, code.name)  # <__main__.Coder object at 0x0000014FA013B780> 毛毛
